import {
  g3x_defineClassProperties,
} from "@g3x/utils";
import {
  registerObject,
  registerObjectFromGuid,
} from "@g3v/utils";

export default function(Ctor) {
  g3x_defineClassProperties(Ctor, [{
    key: 'xbsjFromJSON',
    value: function xbsjFromJSON(jsonObject) {
      (0, _get3.default)(Earth.prototype.__proto__ || (0, _getPrototypeOf2.default)(Earth.prototype),
        'xbsjFromJSON', this).call(this, jsonObject);

      try {
        this.cameraFlight.xbsjFromJSON(jsonObject.cameraFlight);
      } catch (ex) {
        console.log('cameraFlight fromJSON failed', ex);
      }

      try {
        this.weather.xbsjFromJSON(jsonObject.weather);
      } catch (ex) {
        console.log('weather fromJSON failed', ex);
      }

      try {
        this.terrainEffect.xbsjFromJSON(jsonObject.terrainEffect);
      } catch (ex) {
        console.log('terrainEffect fromJSON failed', ex);
      }

      try {
        this.postProcess.xbsjFromJSON(jsonObject.postProcess);
      } catch (ex) {
        console.log('postProcess fromJSON failed', ex);
      }

      try {
        this.effect.xbsjFromJSON(jsonObject.effect);
      } catch (ex) {
        console.log('effect fromJSON failed', ex);
      }
    }

    /**
     * 转化成一个JSON数据对象
     * @description 注意：每次都会创建一个新对象！
     * @method
     * @returns {object} 创建的JSON数据对象
     */

  }, {
    key: 'toJSON',
    value: function toJSON() {
      var jsonObject = (0, _extends3.default)({}, (0, _get3.default)(Earth.prototype.__proto__ || (0,
        _getPrototypeOf2.default)(Earth.prototype), 'toJSON', this).call(this), {
        // cameraViewManager: this.cameraViewManager.toJSON(),  //视角管理器
        cameraFlight: this.cameraFlight.toJSON(), //相机飞行器
        weather: this.weather.toJSON(), //天气
        terrainEffect: this.terrainEffect.toJSON(), //地形效果
        postProcess: this.postProcess.toJSON(), //后处理效果
        effect: this.effect.toJSON() //其他效果
      });

      return jsonObject;
    }
  }, {
    key: 'registerObject',
    value: function registerObject(guid, attachFunc, detachFunc) {
      return registerObject(this, guid, attachFunc, detachFunc);
    }
  }, {
    key: 'registerObjectFromGuid',
    value: function registerObjectFromGuid(selfObject, guidProperty, objectProperty) {
      return registerObjectFromGuid(this, selfObject, guidProperty, objectProperty);
    }

    /**
     * 根据guid获取某个对象
     * @param {string} id 对象的guid
     */

  }, {
    key: 'getObject',
    value: function getObject(id) {
      return this._xbsjObjectsMap.get(id);
    }

    /**
     * 获取某一类对象的集合
     * @param {string} [filterType] 对象类型名
     */

  }, {
    key: 'getAllObjects',
    value: function getAllObjects(filterType) {
      var results = [];
      this._xbsjObjectsMap.forEach(function(xbsjObj, guid) {
        if (!filterType || xbsjObj.xbsjType === filterType) {
          results.push(xbsjObj);
        }
      });

      return results;
    }

    /**
     * 截图
     * @param {number} width 图像宽度，单位像素
     * @param {number} height 图像高度，单位像素
     * @returns {string} 返回图像的base64为字符串
     */

  }, {
    key: 'capture',
    value: function capture(width, height, format) {
      return (0, _capture3.default)(this._scene, width, height, format);
    }

    /**
     * 位置拾取
     * @param {object} movePosition windows窗口坐标，形式如 {x: 10, y: 50 }
     * @param {array} result 返回值一个位置，形式如 [1.0, 0.5, 50.0]，表示[经度, 纬度, 高度]，经纬度以弧度为单位，高度以米为单位
     */

  }, {
    key: 'pickPosition',
    value: function pickPosition(movePosition, result) {
      return (0, _pickPosition3.default)(this._scene, movePosition, result);
    }

    /**
     * 假定物体在屏幕上的大小来计算该物体实际尺寸，单位米
     * @param {array} position 位置，形式如[1.0, 0.5, 50.0]，表示[经度, 纬度, 高度]，经纬度以弧度为单位，高度以米为单位
     * @param {number} screenSize 窗口上的实际像素大小，单位像素
     * @returns {number} 返回实际尺寸大小，单位米
     */
  }, {
    key: 'getSceneSize',
    value: function getSceneSize(position, screenSize) {
      return (0, _getSceneSize3.default)(this._scene, position, screenSize);
    }
  }, {
    key: 'objectsMap',
    get: function get() {
      return this._xbsjObjectsMap;
    }
  }, {
    key: 'objectOpsEvent',
    get: function get() {
      return this._xbsjObjectOpsEvent;
    }
  }, {
    key: 'shortcutAction',
    get() {
      return this.viewerOptions.shortcutAction;
    },
    set(val) {
      return this.viewerOptions.shortcutAction = val;
    }
  }]);
}
